package com.lgkj.utils;

import android.app.Activity;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lgkj.R;

/**
 * Created by Administrator on 2018/6/15 0015.
 */

public class TitleBuilder {
    private View titleView;
    private TextView text;
    private ImageView leftIco;
    private TextView rightText;

    /**
     * 构造方法：用于获取对象
     */
    public TitleBuilder(Activity context) {
        titleView = context.findViewById(R.id.base_title);
        text = titleView.findViewById(R.id.tv_title);
        leftIco = titleView.findViewById(R.id.iv_back);
        rightText = titleView.findViewById(R.id.tv_right);
    }

    /**
     * 用于设置标题栏文字
     */
    public TitleBuilder setRIghtText(String titleText, View.OnClickListener listener) {
        rightText.setVisibility(View.VISIBLE);
        if (!TextUtils.isEmpty(titleText)) {
            rightText.setOnClickListener(listener);
            rightText.setText(titleText);
        }
        return this;
    }

    /**
     * 用于设置标题栏文字
     */
    public TitleBuilder setTitleText(String titleText) {
        if (!TextUtils.isEmpty(titleText)) {
            text.setText(titleText);
        }
        return this;
    }

    /**
     * 用于设置标题栏左边要显示的图片
     */
    public TitleBuilder setLeftIco(int resId) {
        leftIco.setVisibility(resId > 0 ? View.VISIBLE : View.GONE);
        leftIco.setImageResource(resId);
        return this;
    }


    /**
     * 用于设置标题栏左边图片的单击事件
     */
    public TitleBuilder setLeftIcoListening(View.OnClickListener listener) {
        if (leftIco.getVisibility() == View.VISIBLE) {
            leftIco.setOnClickListener(listener);
        }
        return this;
    }

}
